#ifndef PAGE1_WIDGET_H
#define PAGE1_WIDGET_H

#include <QWidget>
#include <QDebug>
#include <QTimer>
#include <stdio.h>
#include <string.h>
#include "ui_welcomewidget.h"
#include "key_rgb_relay.h"
#include "user/tuya_iot_kit.h"


class WelcomeWidget;

#define MAX_SLAVER_COUNT 16

class Page1_Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Page1_Widget(WelcomeWidget *widget);
    ~Page1_Widget();

    void send_get_dev_info_cmd(void);

signals:
    void signal_write_sp_tx_queue(char *s,unsigned int len);

public slots:
    void slot_pb_led_ctrl_all_clicked(bool flag);
    void slot_pb_relay_ctrl_clicked(bool flag);

private slots:

    //RED LED
    void on_pb_led_ctrl_r_clicked();
    void on_pb_brightness_dec_r_clicked();
    void on_pb_brightness_inc_r_clicked();
    void on_horizontalSlider_brightness_r_valueChanged(int value);

    //BLUE LED
    void on_pb_led_ctrl_b_clicked();
    void on_pb_brightness_dec_b_clicked();
    void on_pb_brightness_inc_b_clicked();
    void on_horizontalSlider_brightness_b_valueChanged(int value);

    //GREEN LED
    void on_pb_led_ctrl_g_clicked();
    void on_pb_brightness_dec_g_clicked();
    void on_pb_brightness_inc_g_clicked();
    void on_horizontalSlider_brightness_g_valueChanged(int value);

    void on_pb_relay_ctrl_clicked();
    void on_pb_light_ctrl_clicked();

    void on_pb_clear_screen_clicked();
    void display_msg(QString str);

    void slot_get_dev_node_info(unsigned char *p_data, unsigned char len);
    void slot_slave_notify_info(unsigned char *p_data, unsigned char len);

    void updatetimer_timeout_handler();

private:

    Key_RGB_Relay *key_rgb_relay_ctrl;
    WelcomeWidget *welcomewidget;
    Ui::WelcomeWidget *welcome_ui;
    QTimer *update_timer;

    typedef struct slave_node
    {
        unsigned short slaver_net_id;
        unsigned short slaver_dev_id;
        unsigned short slaver_channel_id;
        unsigned short slaver_dev_type;
        unsigned short online_flag;
    }slave_node_t;

    slave_node_t slaver_node[MAX_SLAVER_COUNT];

    unsigned char slave_count;
    unsigned short slave_index;

    bool all_leds_status;
    bool relay_status;

    void change_all_leds_status();
    void change_relay_status();

};


#endif

